﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Yipusoft.Evaluate.DBUtility;
using Yipusoft.Evaluate.Model;

namespace Yipusoft.Evaluate.DAL
{
    public class Standard
    {
        public bool Insert(StandardInfo Standard)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@TotalScore",SqlDbType.Decimal),
                new SqlParameter("@TaskPer",SqlDbType.Decimal),
                new SqlParameter("@BasePer",SqlDbType.Decimal),
                new SqlParameter("@InspectPer",SqlDbType.Decimal),
                new SqlParameter("@CheckPer",SqlDbType.Decimal)
            };
            parameters[0].Value = Standard.TotalScore;
            parameters[1].Value = Standard.TaskPer;
            parameters[2].Value = Standard.BasePer;
            parameters[3].Value = Standard.InspectPer;
            parameters[4].Value = Standard.CheckPer;
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                int rowAffected = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "AllStandard_Insert", parameters);
                return rowAffected > 0;
            }
        }
        public bool Update(StandardInfo Standard)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@TotalScore",SqlDbType.Decimal),
                new SqlParameter("@TaskPer",SqlDbType.Decimal),
                new SqlParameter("@BasePer",SqlDbType.Decimal),
                new SqlParameter("@InspectPer",SqlDbType.Decimal),
                new SqlParameter("@CheckPer",SqlDbType.Decimal)
            };
            parameters[0].Value = Standard.TotalScore;
            parameters[1].Value = Standard.TaskPer;
            parameters[2].Value = Standard.BasePer;
            parameters[3].Value = Standard.InspectPer;
            parameters[4].Value = Standard.CheckPer;
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                int rowAffected = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "AllStandard_Update", parameters);
                return rowAffected > 0;
            }
        }
        public StandardInfo GetStandard()
        {
            StandardInfo Standard = null;
            SqlParameter[] parameters = {
            };
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "AllStandard_GetDetail", parameters);
                if (dr.Read())
                {
                    Standard = new StandardInfo();
                    Standard.TotalScore = dr.GetDecimal(0);
                    Standard.TaskPer = dr.GetDecimal(1);
                    Standard.BasePer = dr.GetDecimal(2);
                    Standard.InspectPer = dr.GetDecimal(3);
                    Standard.CheckPer = dr.GetDecimal(4);
                }
                return Standard;
            }
        }
    }
}
